<<<<<<< .mine
def isdict(a):
    try:
        a['test']
        return True
    except(TypeError):
        return False
    except(KeyError):
        return True
def equals(a,b):
    equal=False
    different=False
    difference=[]
    for ka,va in a.iteritems():
        for kb,vb in b.iteritems():
            if ka==kb and vb!=va and vb!='' and va!='':
                different=True
            elif ka==kb and vb==va and vb!='':
                equal=True
            elif ka==kb and isdict(vb) and isdict(va):
                if equals(vb,va):
                    equal=True
                else:
                    different=True
    if equal and not different: return True #they are exactly the same
    else: return False #they have no relation at all
def init(files):
    for sinks in files:
        for sink in sinks: sink.files=sink.get_files()
        for sink in sinks:
            for file in sink.files:
                for s in sinks:
                    if s.name!=sink.name:
                        found=False
                        for f in s.files:
                            if equals(f,file):
                                found=True
                        if not found:
                            print 'creating %s to %s' % (file['title'],s.name)
                            file.update({'content':sink.getContent(file)})
                            s.create(file)
def loop(files):
    while 1:
        for sinks in files:
            for sink in sinks:
                get_files=sink.get_files()

                if get_files==None: continue
                
                #check if file deleted or edited
                for file in sink.files:
                    found=False
                    for f in get_files:
                        if equals(file,f):
                            found=True
                    if not found:
                        sink.files.remove(file)
                        for s in sinks:
                            if s.name!=sink.name:
                                print "removing %s from %s" % (file['title'],s.name)
                                for fi in s.files:
                                    if equals(fi,file):
                                        s.remove(fi)
                                        s.files.remove(fi)

                #check if files added
                for file in get_files:
                    found=False
                    for f in sink.files:
                        if equals(file,f):
                            found=True
                    if not found: # file has been added
                        file.update({'content':sink.getContent(file)})
                        sink.files.append(file)
                        for s in sinks:
                            if s.name!=sink.name:
                                print "creating %s to %s" % (file['title'],s.name)
                                s.create(file)
                                s.files.append(file)=======
def isdict(a):
    try:
        a['test']
        return True
    except(TypeError):
        return False
    except(KeyError):
        return True
def equals(a,b):
    equal=False
    different=False
    difference=[]
    for ka,va in a.iteritems():
        for kb,vb in b.iteritems():
            if ka==kb and vb!=va and vb!='' and va!='':
                different=True
            elif ka==kb and vb==va and vb!='':
                equal=True
            elif ka==kb and isdict(vb) and isdict(va):
                if equals(vb,va):
                    equal=True
                else:
                    different=True
    if equal and not different: return True #they are exactly the same
    else: return False #they have no relation at all
def init(files):
    for sinks in files:
        for sink in sinks: sink.files=sink.get_files()
        for sink in sinks:
            for file in sink.files:
                for s in sinks:
                    if s.name!=sink.name:
                        found=False
                        for f in s.files:
                            if equals(f,file):
                                found=True
                            elif f['title']==file['title'] and f['title']!='':
                                found=True
                                print '%s must need updating...' % f['title']
                        if not found:
                            print 'creating %s to %s' % (file['title'],s.name)
                            file.update({'content':sink.getContent(file)})
                            s.create(file)
def loop(files):
    while 1:
        for sinks in files:
            for sink in sinks:
                get_files=sink.get_files()
                
                #check if file deleted or edited
                for file in sink.files:
                    found=False
                    for f in get_files:
                        if equals(file,f):
                            found=True
                    if not found:
                        sink.files.remove(file)
                        for s in sinks:
                            if s.name!=sink.name:
                                print "removing %s from %s" % (file['title'],s.name)
                                for fi in s.files:
                                    if equals(fi,file):
                                        s.remove(fi)
                                        s.files.remove(fi)

                #check if files added
                for file in get_files:
                    found=False
                    for f in sink.files:
                        if equals(file,f):
                            found=True
                    if not found: # file has been added
                        file.update({'content':sink.getContent(file)})
                        sink.files.append(file)
                        for s in sinks:
                            if s.name!=sink.name:
                                print "creating %s to %s" % (file['title'],s.name)
                                s.create(file)
                                s.files.append(file)>>>>>>> .r14
